Skip to content

Integrate nostr-sdk relay options, stream events, and timestamp tweaking#283

Merged
kwsantiago merged 7 commits intomainfrom
nostr-sdk-integration
Feb 26, 2026
Merged

Integrate nostr-sdk relay options, stream events, and timestamp tweaking#283
kwsantiago merged 7 commits intomainfrom
nostr-sdk-integration

Conversation

@kwsantiago
Copy link
Contributor

@kwsantiago kwsantiago commented Feb 26, 2026

Summary by CodeRabbit

  • Improvements

    • More robust relay management with pool-based connections, automatic reconnection, ping monitoring and faster retry behavior for improved reliability.
    • Stream-based event processing and more resilient event parsing/validation (including broader relay-list formats).
    • Event timestamps now use a tweaked timestamp window for improved timing behavior and clock-skew tolerance.
  • Chores

    • Removed chrono dependency.

@kwsantiago kwsantiago self-assigned this Feb 26, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 26, 2026

Warning

Rate limit exceeded

@kwsantiago has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 53 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5c9451b and ab63d7d.

📒 Files selected for processing (1)
  • keep-frost-net/src/node/mod.rs

Walkthrough

Refactors relay management to use the client's relay pool and RelayOptions, migrates agent event consumption to pool-based streams, adds a TIMESTAMP_TWEAK_RANGE constant and applies tweaked timestamps to many emitted events, and replaces chrono timestamps with nostr_sdk::Timestamp across multiple modules.

Changes

Cohort / File(s) Summary
Agent relay & event flow
keep-agent/src/client.rs
Replace direct relay adds with pool().add_relay(..., RelayOptions); add helpers to wait for relay connections; switch from subscribe/notifications to pool.stream_events() and stream.next(); add timestamp tweak on created_at for NostrConnect events; update event parsing/decryption and approval logic.
Node relay handling & defaults
keep-frost-net/src/node/mod.rs, keep-frost-net/src/node/descriptor.rs
Use pool().add_relay(..., default_relay_opts()); add default_relay_opts(); replace chrono timestamps with Timestamp::now() and apply Timestamp::tweaked(TIMESTAMP_TWEAK_RANGE) to descriptor-related events.
Event builders & tag parsing
keep-frost-net/src/event.rs
Replace chrono usage with Timestamp::now() and add .custom_created_at(Timestamp::tweaked(...)) across many EventBuilder paths; refactor tag lookups to TagKind helpers and tighten payload parsing (hex validation, string checks).
NIP-46 server relay & timestamp
keep-nip46/src/server.rs
Add RelayOptions and use client.pool().add_relay(relay_url, opts); apply tweaked created_at to NIP-46 response events.
Core relay config
keep-core/src/relay.rs
Add public constant TIMESTAMP_TWEAK_RANGE: std::ops::Range<u64> = 0..5.
Protocol & tests time source
keep-frost-net/src/protocol.rs, keep-frost-net/Cargo.toml
Switch tests and internal time checks from chrono::Utc::now() to nostr_sdk::Timestamp::now().as_secs(); remove chrono dependency from Cargo.toml.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Agent as AgentClient
participant Pool as ClientPool
participant Relay as Relay
participant Stream as EventStream
participant NIP44 as nip44 (decrypt)

Agent->>Pool: pool().add_relay(url, RelayOptions)
Pool->>Relay: connect()
Relay-->>Pool: Connected
Pool-->>Agent: notify connection (wait_for_any_relay_connection)
Agent->>Pool: stream = pool.stream_events(since, filters)
loop event stream
    Stream->>Agent: next(event)
    Agent->>NIP44: decrypt(event.payload)
    NIP44-->>Agent: decrypted_json
    Agent->>Agent: parse approval (id/error/result) -> Approved/Denied/Pending
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hopped from relay to pool, a tidy little trick,
Tweaked timestamps in my pouch, just five seconds—nice and quick,
Streams hum like clover-choirs, events come down the trail,
I nibble bytes and parse the nuts, then tuck the proofs in mail. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the three main changes: integrating nostr-sdk relay options, adopting stream-based event handling, and adding timestamp tweaking functionality across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch nostr-sdk-integration

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
keep-nip46/src/server.rs (1)

515-516: Consider using a shared constant for timestamp tweak range.

This uses the literal 0..5 while keep-frost-net defines TIMESTAMP_TWEAK_RANGE for the same purpose. For consistency and maintainability, consider extracting this to a shared constant (e.g., in keep-core) or importing it if cross-crate visibility is feasible.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@keep-nip46/src/server.rs` around lines 515 - 516, Replace the hardcoded range
literal 0..5 passed to Timestamp::tweaked with a shared constant (e.g.,
TIMESTAMP_TWEAK_RANGE) to match other crates; update the call in the
EventBuilder creation
(EventBuilder::new(...).custom_created_at(Timestamp::tweaked(...))) to use that
constant, and either import TIMESTAMP_TWEAK_RANGE from the existing
keep-frost-net/keep-core crate or introduce a public constant in keep-core and
use that import so the same identifier is reused across crates for consistency.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@keep-nip46/src/server.rs`:
- Around line 515-516: Replace the hardcoded range literal 0..5 passed to
Timestamp::tweaked with a shared constant (e.g., TIMESTAMP_TWEAK_RANGE) to match
other crates; update the call in the EventBuilder creation
(EventBuilder::new(...).custom_created_at(Timestamp::tweaked(...))) to use that
constant, and either import TIMESTAMP_TWEAK_RANGE from the existing
keep-frost-net/keep-core crate or introduce a public constant in keep-core and
use that import so the same identifier is reused across crates for consistency.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d2e1d96 and 3115871.

📒 Files selected for processing (5)
  • keep-agent/src/client.rs
  • keep-frost-net/src/event.rs
  • keep-frost-net/src/node/descriptor.rs
  • keep-frost-net/src/node/mod.rs
  • keep-nip46/src/server.rs

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
keep-agent/src/client.rs (1)

564-612: LGTM!

The helper functions wait_for_relay_connection and wait_for_any_relay_connection are well-structured:

  • Clear timeout handling with informative error messages
  • 100ms polling interval is reasonable
  • default_relay_opts() provides sensible defaults (reconnect, ping, 10s retry, max 3s latency)

Note: default_relay_opts() is duplicated in keep-frost-net/src/node/mod.rs. Consider extracting to a shared location in keep-core if this configuration should be consistent across components.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@keep-agent/src/client.rs` around lines 564 - 612, The function
default_relay_opts() is duplicated in another crate; extract this helper into a
shared module in keep-core (e.g., a new relay/config helper) and export it so
both keep-agent (where default_relay_opts is defined) and keep-frost-net (where
it’s duplicated) can import the single implementation; update callers in
wait_for_relay_connection and wait_for_any_relay_connection to call the shared
default_relay_opts (remove the local copy) and ensure the shared function
preserves the same settings (reconnect, ping, retry_interval 10s,
adjust_retry_interval, ban_relay_on_mismatch, max_avg_latency 3s) and
appropriate visibility and crate features to avoid breaking consumers.
keep-frost-net/src/node/mod.rs (1)

1177-1185: Consider extracting default_relay_opts() to a shared location.

This function is duplicated identically in keep-agent/src/client.rs (lines 604-612). While the duplication is minor, having a single source of truth for relay configuration would make it easier to maintain consistent behavior across components.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@keep-frost-net/src/node/mod.rs` around lines 1177 - 1185,
default_relay_opts() is duplicated; extract it to a single, shared public
function (e.g., pub fn default_relay_opts() in a new or existing common module
like relay/config or utils) so both modules call the same implementation; ensure
the function is exported (pub) and that the RelayOptions type and Duration are
in scope where it’s used, replace the two local copies with calls to the shared
function, and remove the duplicate definitions so there’s one source of truth
for relay configuration.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@keep-agent/src/client.rs`:
- Around line 564-612: The function default_relay_opts() is duplicated in
another crate; extract this helper into a shared module in keep-core (e.g., a
new relay/config helper) and export it so both keep-agent (where
default_relay_opts is defined) and keep-frost-net (where it’s duplicated) can
import the single implementation; update callers in wait_for_relay_connection
and wait_for_any_relay_connection to call the shared default_relay_opts (remove
the local copy) and ensure the shared function preserves the same settings
(reconnect, ping, retry_interval 10s, adjust_retry_interval,
ban_relay_on_mismatch, max_avg_latency 3s) and appropriate visibility and crate
features to avoid breaking consumers.

In `@keep-frost-net/src/node/mod.rs`:
- Around line 1177-1185: default_relay_opts() is duplicated; extract it to a
single, shared public function (e.g., pub fn default_relay_opts() in a new or
existing common module like relay/config or utils) so both modules call the same
implementation; ensure the function is exported (pub) and that the RelayOptions
type and Duration are in scope where it’s used, replace the two local copies
with calls to the shared function, and remove the duplicate definitions so
there’s one source of truth for relay configuration.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3115871 and 5c9451b.

📒 Files selected for processing (8)
  • keep-agent/src/client.rs
  • keep-core/src/relay.rs
  • keep-frost-net/Cargo.toml
  • keep-frost-net/src/event.rs
  • keep-frost-net/src/node/descriptor.rs
  • keep-frost-net/src/node/mod.rs
  • keep-frost-net/src/protocol.rs
  • keep-nip46/src/server.rs
💤 Files with no reviewable changes (1)
  • keep-frost-net/Cargo.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • keep-nip46/src/server.rs

@kwsantiago kwsantiago merged commit 543691c into main Feb 26, 2026
9 checks passed
@kwsantiago kwsantiago deleted the nostr-sdk-integration branch February 26, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant